function hideDefaultTabBar(_this){
  if (typeof _this.getTabBar === 'function' && _this.getTabBar()) {
    _this.getTabBar().setData({
      isShowTabBar:false,
      selected: 0,
    })
  }
}

// app.js
App({
    //初始化小程序
  onLaunch: function () {
      // 展示本地存储能力
      const logs = wx.getStorageSync('logs') || []
      logs.unshift(Date.now())
      wx.setStorageSync('logs', logs)
  
      // 登录
      wx.login({
        success: res => {
          // 发送 res.code 到后台换取 openId, sessionKey, unionId
        }
      })

    //隐藏系统tabbar
    hideDefaultTabBar(this);
    // wx.hideTabBar();
    
  },
  onShow: function(){
    //隐藏系统tabbar
    hideDefaultTabBar(this);
    // wx.hideTabBar();
  },
  // 自定义导航
  renderTabbar: function () {
    let tabbar = this.globalData.tabBar;
    let currentPages = getCurrentPages();
    let _this = currentPages[currentPages.length - 1];
    let pagePath = _this.route;
    (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
    // console.log('tabbar:',tabbar,'pagePath:',pagePath);
    for (let i in tabbar.list) {
      tabbar.list[i].selected = false;
      (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
    }
    
    _this.setData({
      tabbar: tabbar
    });
  },
  //定义配置参数
  globalData: {
    userInfo: null,
    isIphoneX: false,
    tabBar: {
      "backgroundColor": "#ffffff",
      "color": "#979795",
      // "selectedColor": "#1c1c1b",
      "list": [
        {
          "pagePath": "/pages/lesson/lesson",
          "iconPath": "/images/nav/lesson.png",
          "selectedIconPath": "/images/nav/lesson-on.png",
          "text": "摘镜小课堂"
        },
        {
          "pagePath": "/pages/index/index",
          "iconPath": "/images/nav/home.png",
          "selectedIconPath": "/images/nav/home-on.png",
          "text": "首页"
        },
        {
          "pagePath": "/pages/usercenter/usercenter",
          "iconPath": "/images/nav/my.png",
          "selectedIconPath": "/images/nav/my-on.png",
          "text": "我的"
        }
      ]
    }
  },
})
